
package com.feib.soeasy.job.importor;

import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.feib.soeasy.job.util.MailContentTemplate;
import com.feib.soeasy.model.ColumnValidateError;


/**
 * @title (#)FileImportMailContent.java<br>
 * @description <br>
 * @author Jimmy Liu<br>
 * @version 1.0.0 2010/11/25
 * @copyright Far Eastern International Bank Copyright (c) 2010<br>
 * @2010/12/5 create by Jimmy Liu<br>
 */
public class FileImportMailContent extends MailContentTemplate {


    private List<ColumnValidateError> columnValidateErrors;
    
    private boolean isToBank = false;
    
    /**
     * @param messageTile
     * @param paragraphs
     */
    public FileImportMailContent(String messageTile, String[] paragraphs, String htmlMailFolder) {
        super(messageTile, paragraphs, htmlMailFolder);
    }
    
    /* (non-Javadoc)
     * @see com.feib.soeasy.job.util.MailContentTemplate#getOtherContent(java.lang.StringBuffer)
     */
    @Override
    protected StringBuffer getOtherContent(StringBuffer html) {

        if (null != columnValidateErrors && 0 != columnValidateErrors.size())
        {
            if (isToBank)
            {
                html.append("            <p>系統錯誤訊息</p>");
                html.append("            <table border=\"1\" style=\"width: 100%; \">");
                html.append("                   <tr style=\"background: #f4e3e3;\">");
                html.append("                   <th>行號</th>");
                html.append("                    <th>系統訊息</th>");
                
                html.append("                </tr>");
                for(ColumnValidateError error : columnValidateErrors)
                {
                    if (StringUtils.isNotEmpty(error.getExceptionMessage()))
                    {
                        html.append("                <tr>");
                        html.append("                   <th>").append(null == error.getLineNumber() ? "" : error.getLineNumber()).append("</th>");
                        html.append("                   <td>").append(null == error.getExceptionMessage() ? "" : error.getExceptionMessage()).append("</td>");
                        html.append("                </tr>");
                    }
                }
                html.append("            </table>");
            }
            
            
            html.append("            <p>錯誤原因如下</p>");
            html.append("            <table border=\"1\" style=\"width: 100%; \">");
            html.append("                <tr style=\"background: #f4e3e3;\">");
            html.append("                   <th>行號</th>");
            html.append("                   <th>欄位名稱</th>");
            html.append("                   <th>錯誤訊息</th>");
            
            html.append("                </tr>");
            for(ColumnValidateError error : columnValidateErrors)
            {
                html.append("                <tr>");
                html.append("                   <th>").append(null == error.getLineNumber() ? "" : error.getLineNumber()).append("</th>");
                html.append("                   <th>").append(null == error.getColumnName() ? "" : error.getColumnName()).append("</th>");
                html.append("                   <td>").append(null == error.getErrorMessage() ? "" : error.getErrorMessage()).append("</td>");
                html.append("                </tr>");
            }
            html.append("            </table>");
            
            
        }
        
        return html;
    }
    
    /**
     * @return the columnValidateErrors
     */
    public List<ColumnValidateError> getColumnValidateErrors() {
        return columnValidateErrors;
    }

    
    /**
     * @param columnValidateErrors the columnValidateErrors to set
     */
    public void setColumnValidateErrors(List<ColumnValidateError> columnValidateErrors) {
        this.columnValidateErrors = columnValidateErrors;
    }

    
    /**
     * @return the isToBank
     */
    public boolean isToBank() {
        return isToBank;
    }

    
    /**
     * @param isToBank the isToBank to set
     */
    public void setToBank(boolean isToBank) {
        this.isToBank = isToBank;
    }

}
